package com.ruoyi.manufacturer.demo;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.manager.AsyncManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.TimerTask;

/**
 * 等待消息通过http推送
 */
@RestController
public class DemoApi {
    @Autowired
    private  DemoHandler demoHandler;

    /**
     * 接入消息并处理
     * @param msg
     * @return
     */
    @PostMapping("/demo/push")
    public AjaxResult push(@RequestBody String msg){
        //异步处理
        AsyncManager.me().execute(new TimerTask() {
            @Override
            public void run() {
                demoHandler.process(msg);
            }
        });
        return AjaxResult.success();
    }
}
